<template>
  <el-dialog :title="发货" :close-on-click-modal="false" :visible.sync="visible">
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="120px"
    >
      <el-form-item label="订单号" prop="orderSn">
        <el-input v-model="dataForm.orderSn" disabled placeholder="订单号"></el-input>
      </el-form-item>
      <el-form-item label="订单创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" disabled placeholder="create_time"></el-input>
      </el-form-item>
      <el-form-item label="物流公司(配送方式)" prop="deliveryCompany">
        <el-input v-model="dataForm.deliveryCompany" placeholder="物流公司(配送方式)"></el-input>
      </el-form-item>
      <el-form-item label="物流单号" prop="deliverySn">
        <el-input v-model="dataForm.deliverySn" placeholder="物流单号"></el-input>
      </el-form-item>
      <el-form-item label="自动确认时间（天）" prop="autoConfirmDay">
        <el-input v-model="dataForm.autoConfirmDay" placeholder="自动确认时间（天）"></el-input>
      </el-form-item>
      <el-form-item label="订单备注" prop="note">
        <el-input v-model="dataForm.note" placeholder="订单备注"></el-input>
      </el-form-item>
      <el-form-item label="发货时间" prop="deliveryTime">
        <el-input v-model="dataForm.deliveryTime" placeholder="发货时间"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        memberId: "",
        orderSn: "",
        couponId: "",
        createTime: "",
        memberUsername: "",
        totalAmount: "",
        payAmount: "",
        freightAmount: "",
        promotionAmount: "",
        integrationAmount: "",
        couponAmount: "",
        discountAmount: "",
        payType: "",
        sourceType: "",
        status: "",
        deliveryCompany: "",
        deliverySn: "",
        autoConfirmDay: "",
        integration: "",
        growth: "",
        billType: "",
        billHeader: "",
        billContent: "",
        billReceiverPhone: "",
        billReceiverEmail: "",
        receiverName: "",
        receiverPhone: "",
        receiverPostCode: "",
        receiverProvince: "",
        receiverCity: "",
        receiverRegion: "",
        receiverDetailAddress: "",
        note: "",
        confirmStatus: "",
        deleteStatus: "",
        useIntegration: "",
        paymentTime: "",
        deliveryTime: "",
        receiveTime: "",
        commentTime: "",
        modifyTime: ""
      },
      dataRule: {
        
        deliveryCompany: [
          {
            required: true,
            message: "物流公司(配送方式)不能为空",
            trigger: "blur"
          }
        ],
        deliverySn: [
          { required: true, message: "物流单号不能为空", trigger: "blur" }
        ],
        
        note: [
          { required: true, message: "订单备注不能为空", trigger: "blur" }
        ],
        confirmStatus: [
          {
            required: true,
            message: "确认收货状态[0->未确认；1->已确认]不能为空",
            trigger: "blur"
          }
        ],
        deleteStatus: [
          {
            required: true,
            message: "删除状态【0->未删除；1->已删除】不能为空",
            trigger: "blur"
          }
        ],
        useIntegration: [
          {
            required: true,
            message: "下单时使用的积分不能为空",
            trigger: "blur"
          }
        ],
        deliveryTime: [
          { required: true, message: "发货时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/order/order/info/${this.dataForm.id}`),
            method: "get",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.memberId = data.order.memberId;
              this.dataForm.orderSn = data.order.orderSn;
              this.dataForm.couponId = data.order.couponId;
              this.dataForm.createTime = data.order.createTime;
              this.dataForm.memberUsername = data.order.memberUsername;
              this.dataForm.totalAmount = data.order.totalAmount;
              this.dataForm.payAmount = data.order.payAmount;
              this.dataForm.freightAmount = data.order.freightAmount;
              this.dataForm.promotionAmount = data.order.promotionAmount;
              this.dataForm.integrationAmount = data.order.integrationAmount;
              this.dataForm.couponAmount = data.order.couponAmount;
              this.dataForm.discountAmount = data.order.discountAmount;
              this.dataForm.payType = data.order.payType;
              this.dataForm.sourceType = data.order.sourceType;
              this.dataForm.status = data.order.status;
              this.dataForm.deliveryCompany = data.order.deliveryCompany;
              this.dataForm.deliverySn = data.order.deliverySn;
              this.dataForm.autoConfirmDay = data.order.autoConfirmDay;
              this.dataForm.integration = data.order.integration;
              this.dataForm.growth = data.order.growth;
              this.dataForm.billType = data.order.billType;
              this.dataForm.billHeader = data.order.billHeader;
              this.dataForm.billContent = data.order.billContent;
              this.dataForm.billReceiverPhone = data.order.billReceiverPhone;
              this.dataForm.billReceiverEmail = data.order.billReceiverEmail;
              this.dataForm.receiverName = data.order.receiverName;
              this.dataForm.receiverPhone = data.order.receiverPhone;
              this.dataForm.receiverPostCode = data.order.receiverPostCode;
              this.dataForm.receiverProvince = data.order.receiverProvince;
              this.dataForm.receiverCity = data.order.receiverCity;
              this.dataForm.receiverRegion = data.order.receiverRegion;
              this.dataForm.receiverDetailAddress =
                data.order.receiverDetailAddress;
              this.dataForm.note = data.order.note;
              this.dataForm.confirmStatus = data.order.confirmStatus;
              this.dataForm.deleteStatus = data.order.deleteStatus;
              this.dataForm.useIntegration = data.order.useIntegration;
              this.dataForm.paymentTime = data.order.paymentTime;
              this.dataForm.deliveryTime = data.order.deliveryTime;
              this.dataForm.receiveTime = data.order.receiveTime;
              this.dataForm.commentTime = data.order.commentTime;
              this.dataForm.modifyTime = data.order.modifyTime;
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/order/order/${"update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              memberId: this.dataForm.memberId,
              orderSn: this.dataForm.orderSn,
              couponId: this.dataForm.couponId,
              createTime: this.dataForm.createTime,
              memberUsername: this.dataForm.memberUsername,
              totalAmount: this.dataForm.totalAmount,
              payAmount: this.dataForm.payAmount,
              freightAmount: this.dataForm.freightAmount,
              promotionAmount: this.dataForm.promotionAmount,
              integrationAmount: this.dataForm.integrationAmount,
              couponAmount: this.dataForm.couponAmount,
              discountAmount: this.dataForm.discountAmount,
              payType: this.dataForm.payType,
              sourceType: this.dataForm.sourceType,
              status: this.dataForm.status,
              deliveryCompany: this.dataForm.deliveryCompany,
              deliverySn: this.dataForm.deliverySn,
              autoConfirmDay: this.dataForm.autoConfirmDay,
              integration: this.dataForm.integration,
              growth: this.dataForm.growth,
              billType: this.dataForm.billType,
              billHeader: this.dataForm.billHeader,
              billContent: this.dataForm.billContent,
              billReceiverPhone: this.dataForm.billReceiverPhone,
              billReceiverEmail: this.dataForm.billReceiverEmail,
              receiverName: this.dataForm.receiverName,
              receiverPhone: this.dataForm.receiverPhone,
              receiverPostCode: this.dataForm.receiverPostCode,
              receiverProvince: this.dataForm.receiverProvince,
              receiverCity: this.dataForm.receiverCity,
              receiverRegion: this.dataForm.receiverRegion,
              receiverDetailAddress: this.dataForm.receiverDetailAddress,
              note: this.dataForm.note,
              confirmStatus: this.dataForm.confirmStatus,
              deleteStatus: this.dataForm.deleteStatus,
              useIntegration: this.dataForm.useIntegration,
              paymentTime: this.dataForm.paymentTime,
              deliveryTime: this.dataForm.deliveryTime,
              receiveTime: this.dataForm.receiveTime,
              commentTime: this.dataForm.commentTime,
              modifyTime: this.dataForm.modifyTime
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
